<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/7/11 0011
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
    <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
    <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>
</head>
<body>
<%--<form action="rest/page/information/add" method="post" enctype="multipart/form-data">--%>
    <%--<input name="publisherId" type="text"/> publisherName<br>--%>
    <%--<input name="informationName" type="text"/>请输入文件名字<br>--%>
    <%--<input name="informationContent" type="text"/>请输入文件内容<br>--%>
    <%--<input name="jsonClass" type="text">--%>
    <%--请选择这次要选的班级<br>--%>
    <%--<input name="file" type="file"/>请选择文件<br>--%>
    <%--<input value="提交" type="submit">--%>
<%--</form>--%>
<div style="margin:20px 0;"></div>

<input class="easyui-searchbox" data-options="prompt:'请输入资料名称或者发布人id',searcher:doSearch" style="width:300px">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'是否要删除当前所选择的资料'" style="width:200px;height:75px;text-align: center;">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delStudent()">确认删除当前资料</a>
</div>
<table id="dg" title="资料信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
    <thead>
    <tr>
        <th field="informationId" width="90">资料编号</th>
        <th field="informationName" width="100">资料名字</th>
        <th field="releaseTime" width="90">发布时间</th>
        <th field="readNumber" width="90">阅读数量</th>
        <th field="publisherName" width="100">发布人id</th>
        <th field="informationContent" width="600">资料内容</th>
    </tr>
    </thead>
</table>

<script>
    var i = 1;
    function pagerFilter(data){
        if(i==1&&data[0]!=null){
            var to = data[0].total;
            var wh = data[0].wh;
        }else if(i==2&&data!=null){
            var to = data.total;
            var wh = data.wh;
        }else{
            var to = 0;
            var wh = "";
        }
        if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
            data = {
                total:to,
                rows: data,
                wh:wh
            }
            i=2;
        }
        var dg = $(this);
        var opts = dg.datagrid('options');
        var pager = dg.datagrid('getPager');
        pager.pagination({
            onSelectPage:function(pageNum, pageSize){
                opts.pageNumber = pageNum;
                opts.pageSize = pageSize;
                pager.pagination('refresh',{
                    pageNumber:pageNum,
                    pageSize:pageSize
                });
                var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
                data.rows = (getData(start,parseInt(opts.pageSize),wh));
                dg.datagrid('loadData',data);
            }
        });
        return data;
    }

    $(function(){
        var editFlag = undefined;
        $('#dg').datagrid({
            toolbar:[{
                text:'删除所选中的一条信息',
                iconCls:'icon-remove',
                handler:function(){
                    $('#test').window('open');
                }
            }]})

        $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
    });
    function delStudent(){
        var row = $('#dg').datagrid('getSelected');
        if (delData(row.informationId)==200){
            var index = $('#dg').datagrid('getRowIndex', row);
            alert("成功")
            $('#test').window('close');
            $('#dg').datagrid('deleteRow', index);
        }else{
            alert("删除失败")
        }
    }
    function delData(s){
        var code1 = 0;
        $.ajax({
            method : 'GET',
            url : 'rest/page/manageInformation/del?manageId=${user.teacherid}&informationId='+s+'',
            async : false,
            dataType : 'json',
            success : function(code) {
                code1 = code.code
            },
            error : function() {
                alert('error');
            }
        });
        return code1
    }

    function getData(r,p,s){
        var infor_data = [];
        var total = 0;
        $.ajax({
            method : 'POST',
            url : 'rest/page/stuInformation/select',
            data:{"startrow":r,"pageSize":p,"informationName": s,"manageId":${user.teacherid }},
            async : false,
            dataType : 'json',
            success : function(data) {
                infor_data = data.data
                total = data.total
            },
            error : function() {
                alert('error');
            }
        });
        var rows = [];
        for(var i=0; i< infor_data.length; i++){
            rows.push({
                total:total,
                wh:s,
                informationId:infor_data[i].informationId,
                informationName:infor_data[i].informationName,
                releaseTime:infor_data[i].releaseTime,
                readNumber:infor_data[i].readNumber,
                publisherName:infor_data[i].publisherName,
                informationContent:infor_data[i].informationContent
            });
        }
        return rows;
    }

    function doSearch(value){
        var value1 = value+""
         i = 1;
        $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value1));
    }
</script>
</body>
</html>
